package zy.blue7.gui.netty.custom.qq.message.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import zy.blue7.gui.netty.custom.qq.message.Message;

import java.io.Serializable;

/**
 * @author blue7
 * @version 1.0
 * @date 2022/2/28 9:01
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result<T> implements Message , Serializable {

    private static final String SUCCESS_CODE = "200";
    private static final String SUCCESS_MESSAGE = "SUCCESS";
    private static final String FAIL_CODE = "444";
    private static final String FAIL_MESSAGE = "FAILED";


    /**
     * 返回状态码
     */
    private String code;
    /**
     * 返回结果
     */
    private T result;
    /**
     * 返回消息
     */
    private String message;

    public static Result<Boolean> success() {
        return new ResultBuilder<Boolean>().code(SUCCESS_CODE).message(SUCCESS_MESSAGE).result(Boolean.TRUE).build();
    }


    public static <T> Result<T> success(T result) {
        return new ResultBuilder<T>().code(SUCCESS_CODE).message(SUCCESS_MESSAGE).result(result).build();
    }

    public static <T> Result<T> success(T result, String message) {
        return new ResultBuilder<T>().code(SUCCESS_CODE).message(message).result(result).build();
    }

    public static <T> Result<T> success(T result, String message, String code) {
        return new ResultBuilder<T>().code(code).message(message).result(result).build();
    }

    public static Result<Boolean> failed() {
        return new ResultBuilder<Boolean>().code(FAIL_CODE).message(FAIL_MESSAGE).result(null).build();
    }

    public static Result<Boolean> failed(String msg) {
        return new ResultBuilder<Boolean>().code(FAIL_CODE).message(msg).result(false).build();
    }

    public static <T> Result<T> failed(String message, T result) {
        return new ResultBuilder<T>().code(FAIL_CODE).message(message).result(result).build();
    }

    public static <T> Result<T> failed(String code, String message, T result) {
        return new ResultBuilder<T>().code(code).message(message).result(result).build();
    }

    @Override
    public String getFrom() {
        return null;
    }

    @Override
    public String getTo() {
        return null;
    }
}
